# Contributor: Sören Tempel <soeren+alpine@soeren-tempel.net>
# Maintainer: Alex Denes <caskd@redxen.eu>
pkgname=xonotic
pkgver=0.8.6
pkgrel=0
pkgdesc="A free, fast-paced crossplatform first-person shooter"
url="https://www.xonotic.org/"
arch="x86 x86_64 aarch64 armv7 armhf ppc64le"
license="GPL-2.0-or-later"
depends="xonotic-data"
makedepends="autoconf
	automake
	libtool
	alsa-lib-dev
	curl-dev
	libjpeg-turbo-dev
	libxpm-dev
	libxxf86vm-dev
	sdl2-dev
	libpng-dev
	mesa-dev
	gmp-dev"
subpackages="$pkgname-server $pkgname-sdl $pkgname-glx"
options="!check"
source="$pkgname-$pkgver.zip::http://dl.xonotic.org/xonotic-$pkgver-source.zip
	xonotic-sdl.desktop
	xonotic-glx.desktop"
builddir="$srcdir"/Xonotic

build() {
	local r
	for r in sv sdl cl; do
		make -C "$builddir"/source/darkplaces \
			CPUOPTIMIZATIONS="$CFLAGS" \
			DP_FS_BASEDIR="/usr/share/$pkgname" \
			DP_LINK_TO_LIBJPEG=1 \
			"$r"-release
	done

	cd "$builddir"/source/d0_blind_id
	sh autogen.sh
	./configure \
		--build=$CBUILD \
		--host=$CHOST \
		--prefix=/usr \
		--sysconfdir=/etc \
		--mandir=/usr/share/man \
		--localstatedir=/var
	make
}

package() {
	cd "$builddir"/source/d0_blind_id
	make DESTDIR="$pkgdir" install

	cd "$pkgdir"/usr
	rm -r include
	cd lib
	rm -r pkgconfig -- *.a

	local size
	for size in 16 22 24 32 48 64 128 256 512; do
		install -Dm644 "$builddir"/misc/logos/icons_png/xonotic_"$size".png \
			"$pkgdir"/usr/share/icons/hicolor/"$size"x"$size"/apps/xonotic.png
	done
}

server() {
	pkgdesc="$pkgdesc (Server)"
	depends="xonotic"

	mkdir -p "$subpkgdir"/usr/bin
	install -Dm755 "$builddir"/source/darkplaces/darkplaces-dedicated \
		"$subpkgdir"/usr/bin/xonotic-dedicated
}

sdl() {
	pkgdesc="$pkgdesc (SDL client)"
	depends="xonotic"

	mkdir -p "$subpkgdir"/usr/bin
	install -Dm755 "$builddir"/source/darkplaces/darkplaces-sdl \
		"$subpkgdir"/usr/bin/xonotic-sdl

	mkdir -p "$subpkgdir"/usr/share/applications
	install -Dm644 "$srcdir"/xonotic-sdl.desktop \
		"$subpkgdir"/usr/share/applications/xonotic-sdl.desktop
}

glx() {
	pkgdesc="$pkgdesc (GLX client)"
	depends="xonotic"

	mkdir -p "$subpkgdir"/usr/bin
	install -Dm755 "$builddir"/source/darkplaces/darkplaces-glx \
		"$subpkgdir"/usr/bin/xonotic-glx

	mkdir -p "$subpkgdir"/usr/share/applications
	install -Dm644 "$srcdir"/xonotic-glx.desktop \
		"$subpkgdir"/usr/share/applications/xonotic-glx.desktop
}

sha512sums="
88aa9cf35aa8e4b067dcc313037414fbc3a3769d60e88097ae8a3fbd2343369e2e4eff454b19d8a59b9c0bcbe183ec6eb289f35fa9f36564a300a3664c0e9498  xonotic-0.8.6.zip
963273811453f713ab70f5d12b918c1513a9a7995cd1d2572f0b9060d945391bf7db4ae04ae586531ecf3a088f837803a66ac267d9285928d8b2e82c98b7158b  xonotic-sdl.desktop
2e06d588d68d629a9690b4dd3372c7ad77b240afcd86cf0cdf2de15548d3feaa0e446df1a29339be4593d23bfcf389930bdd1d7021f1e2558d70bb15e28646bd  xonotic-glx.desktop
"
